1
00:00:00,930 --> 00:00:08,160
In this lesson we're going to set up 10 support tensor board is going to run locally on our machine

2
00:00:08,640 --> 00:00:12,970
and it's going to allow us to track how our training is going.

3
00:00:13,050 --> 00:00:20,940
Our model is doing how it's evolving and learning as the training progresses and it allows us to easily

4
00:00:20,940 --> 00:00:24,850
compare different models and their performance.

5
00:00:24,900 --> 00:00:29,420
Now if you're following along using Google collaborate try notebooks.

6
00:00:29,520 --> 00:00:32,330
This lesson is going to be a lot less relevant.

7
00:00:32,550 --> 00:00:38,450
And you're welcome to skip it but if you're running this locally on your machine like the way I am.

8
00:00:38,640 --> 00:00:40,860
Then follow along with me.

9
00:00:41,160 --> 00:00:50,670
Let's insert a markdown cell here that's going to read tensor board and maybe parentheses visualizing

10
00:00:51,600 --> 00:00:59,000
learning that we were going to set up tents board is going to require a couple of steps.

11
00:00:59,220 --> 00:01:07,290
So tensor board is going to read and write to our disk to our hard disk and it's going to need to know

12
00:01:07,710 --> 00:01:10,590
where to read and write its files.

13
00:01:10,590 --> 00:01:16,890
So what we're gonna do is we're going to set up a special folder for all the files that tensor board

14
00:01:16,890 --> 00:01:24,300
is going to use on our machine and we're gonna set up this folder programmatically in our Jupiter notebook.

15
00:01:24,300 --> 00:01:28,560
So scroll back up to your inputs and there you should see.

16
00:01:28,560 --> 00:01:37,060
Import os if you haven't got this added now and can add a couple of more import statements.

17
00:01:37,320 --> 00:01:40,080
For starters Rasch going to import 10 support.

18
00:01:40,320 --> 00:01:49,080
So from Caris don't callbacks import tensor board.

19
00:01:49,200 --> 00:01:56,790
The second thing that we're gonna import is a handy function from the time module so we'll see from

20
00:01:57,270 --> 00:02:04,070
time import s t r f time.

21
00:02:04,120 --> 00:02:08,880
This will give us a very quick way of getting the hour and the minute of the current time.

22
00:02:09,110 --> 00:02:13,200
And you're gonna see how we're going to use this in a minute as well.

23
00:02:13,200 --> 00:02:22,360
So shift enter on the cell and scroll back down to your constants and we're going to add the folder

24
00:02:22,360 --> 00:02:24,860
name that we're going to create.

25
00:02:24,880 --> 00:02:33,610
So we'll call this constant log on underscore score Diaw directory is equal to single quotes tensor

26
00:02:33,610 --> 00:02:44,320
board underscore C I F A R on the score logs and then we'll put a forward slash at the end we will shortly

27
00:02:44,440 --> 00:02:49,030
create this folder here in a side project folder.

28
00:02:49,390 --> 00:02:55,180
So let's hit shift enter on our constants scroll back down to where we're gonna be setting up tents

29
00:02:55,200 --> 00:03:00,440
aboard and let's write our code for our Folder creation.

30
00:03:00,670 --> 00:03:07,030
The first thing that we're gonna decide on is a folder name so check it out folder on a school name

31
00:03:07,270 --> 00:03:11,290
it's gonna be equal to and here will provide a string.

32
00:03:11,410 --> 00:03:12,640
So it'll be an F string.

33
00:03:12,940 --> 00:03:17,850
So let's call it model on a score one at.

34
00:03:18,280 --> 00:03:23,140
And here we're gonna add some curly braces and we're gonna get the current our.

35
00:03:23,260 --> 00:03:25,740
And the current minute for the time.

36
00:03:25,890 --> 00:03:34,540
So we're gonna use that s t r f time function and we're going to open some parentheses inside.

37
00:03:34,910 --> 00:03:42,620
And here we're gonna use double quotes and then we'll have % h space percent.

38
00:03:42,640 --> 00:03:47,070
And now if this looks very mysterious to you.

39
00:03:47,080 --> 00:03:52,660
Let's print this out so print folder on a score name and you'll see what this does.

40
00:03:53,200 --> 00:04:01,850
So if I had shift enter on the cell right now you'll see the string model on a square one at 17 0 6.

41
00:04:01,860 --> 00:04:07,670
So if you look up here at my time it's Monday 5 0 6.

42
00:04:07,840 --> 00:04:08,980
Where am I going with this.

43
00:04:09,370 --> 00:04:17,290
Well I want the current time to be included in my folder name because if I run my code more than once

44
00:04:17,710 --> 00:04:20,550
then I'll get different sub folders setup.

45
00:04:20,590 --> 00:04:28,000
Every time I run my model and this allows me to keep track of what I'm doing and what's going on.

46
00:04:28,000 --> 00:04:33,280
Now I'm actually not going to force you to use the same convention that I'm using him for naming my

47
00:04:33,280 --> 00:04:41,200
folders if you'd like to pull out a different value from that current time then head over to the documentation

48
00:04:41,200 --> 00:04:42,960
for SDR f time.

49
00:04:42,970 --> 00:04:51,790
This is built in into python and scroll down here to this table and here you can see what the different

50
00:04:51,790 --> 00:04:54,360
parameters are that you can pull out.

51
00:04:54,400 --> 00:05:04,540
So I've pulled out % h the 24 hour clock time alongside with capital and the minute the zero pad a decimal

52
00:05:04,540 --> 00:05:06,200
number.

53
00:05:06,280 --> 00:05:11,950
Now if you want to pull out the second as well you can do that with percent s and if you wanted to pull

54
00:05:11,950 --> 00:05:16,810
out the weekday or the month then these are the parameters that you want to use.

55
00:05:17,950 --> 00:05:23,110
So if you want to play around with this a little bit then pause the video and give this a go see what

56
00:05:23,110 --> 00:05:23,840
you can pull out.

57
00:05:24,540 --> 00:05:30,670
Otherwise let's delete this line here and let's actually create our directory.

58
00:05:30,670 --> 00:05:38,310
So the way we're gonna do this is with our OS module operating system OS dot path.

59
00:05:38,560 --> 00:05:40,870
Don't join.

60
00:05:41,170 --> 00:05:43,930
We'll create our folder path for us.

61
00:05:44,260 --> 00:05:45,850
So what are we going to join.

62
00:05:45,850 --> 00:05:53,920
We're going to join our root directory our log underscored directory from upstairs in the constant section

63
00:05:54,700 --> 00:05:57,100
alongside with our folder name.

64
00:05:58,210 --> 00:06:01,480
So this will create a path for us.

65
00:06:01,480 --> 00:06:09,640
And with this path we can actually make a directory including a sub directory so setting up two folders

66
00:06:09,760 --> 00:06:14,320
in a row the way we're gonna do this is with OS.

67
00:06:14,320 --> 00:06:16,650
Don't make D.

68
00:06:16,660 --> 00:06:21,990
IRS make directories and this will need a path.

69
00:06:22,090 --> 00:06:28,000
In other words this value should actually go between these parentheses.

70
00:06:28,000 --> 00:06:30,390
So you can see that the paths are quite important.

71
00:06:30,460 --> 00:06:37,240
So let's give them their own variable to make this code a lot easier and less nested Diaw are underscore

72
00:06:37,540 --> 00:06:40,440
paths and we'll put that in here.

73
00:06:40,640 --> 00:06:42,810
Are on a score paths.

74
00:06:43,310 --> 00:06:49,780
Now what I'll do is I'll make this window slightly smaller and bring up my project folder here on the

75
00:06:49,780 --> 00:06:54,820
side so you can see what happens as I execute this cell.

76
00:06:54,820 --> 00:06:55,620
Did you spot it.

77
00:06:57,100 --> 00:07:03,210
Here's my tensor board on a score CFR underscore logs folder and then inside this folder.

78
00:07:03,280 --> 00:07:11,050
Got a sub folder called model on a score one at seventeen twelve brilliant right.

79
00:07:12,280 --> 00:07:17,170
Let's see what happens when I execute the cell again in this case.

80
00:07:17,170 --> 00:07:20,620
I've got an error my code just failed.

81
00:07:20,620 --> 00:07:23,450
If I scroll down I can see why.

82
00:07:23,560 --> 00:07:27,280
Error number seventeen file exists.

83
00:07:27,430 --> 00:07:34,000
Python did not like executing this cell again when the folder already existed.

84
00:07:34,000 --> 00:07:36,580
So if I delete this folder it should work in theory right.

85
00:07:36,580 --> 00:07:37,820
So I deleted it.

86
00:07:37,960 --> 00:07:45,680
Hit shift enter and I get my folder being created in my cell executing without an error.

87
00:07:45,760 --> 00:07:48,250
So how can we make this a little bit more failsafe.

88
00:07:48,250 --> 00:07:54,290
How can we add some code here to handle these errors if there are any.

89
00:07:54,340 --> 00:07:58,960
The python pattern that we're gonna adopt here is the try block.

90
00:07:58,960 --> 00:08:08,410
So if you write try semicolon and then tab this line of code over so that it is nested inside this try

91
00:08:08,410 --> 00:08:09,650
statement here.

92
00:08:10,000 --> 00:08:16,930
Then python will try to execute this code and if it gets an error then it gives us a chance to handle

93
00:08:17,020 --> 00:08:17,650
the error.

94
00:08:18,130 --> 00:08:21,580
So let's do just that on the next line.

95
00:08:21,790 --> 00:08:29,580
Use the keyword except and the except keyword will be followed by the kind of error that we're gonna

96
00:08:29,590 --> 00:08:32,430
get we're gonna get an OS error.

97
00:08:32,500 --> 00:08:38,140
So that's capital O capital S capital E and then we're going to try and print this era.

98
00:08:38,140 --> 00:08:48,130
So first what it will do is we'll store this error as a variable called E R R and then I'll Addy semicolon

99
00:08:48,130 --> 00:09:00,490
here at the end and then in the next line nested inside except I'll print e r r r dot s t r error.

100
00:09:00,490 --> 00:09:05,760
This will convert our error to a string and allow us to print it out.

101
00:09:06,310 --> 00:09:11,650
The very last thing I want to do is I want to write a success message.

102
00:09:11,650 --> 00:09:16,650
If everything worked splendidly so I'll add an else clause here.

103
00:09:16,720 --> 00:09:24,160
This is gonna be at the same level as our try and our except block and all it's gonna do is print out

104
00:09:24,520 --> 00:09:29,680
the message successfully created the rectory.

105
00:09:30,430 --> 00:09:31,910
So what are we doing here.

106
00:09:32,500 --> 00:09:36,280
Well we're going to try to create these folders if we have an error.

107
00:09:36,340 --> 00:09:42,290
We're going to print out the error below the cell and otherwise we're gonna print out success.

108
00:09:42,400 --> 00:09:43,790
That's all we're gonna do.

109
00:09:43,870 --> 00:09:45,280
So let's try this out.

110
00:09:45,310 --> 00:09:52,220
Let's see what happens when I execute the cell create the directory and then execute the cell again.

111
00:09:52,330 --> 00:09:59,050
In this case all that happens is we handle the error and the error rates of file exists.

112
00:09:59,050 --> 00:10:04,230
So no directories are created and there's nothing else we have to do.

113
00:10:04,300 --> 00:10:05,490
Brilliant.

114
00:10:05,650 --> 00:10:11,930
Let me quickly go to you and toggle my head so that I've got a little bit more screen real estate.

115
00:10:12,070 --> 00:10:17,320
Now all we've done so far is talk to her operating system and create some folders.

116
00:10:17,320 --> 00:10:21,540
We actually haven't set up tents aboard yet tense aboard.

117
00:10:21,560 --> 00:10:29,830
It's actually very very simple to setup a hall we need to do is call tense aboard open parentheses and

118
00:10:29,830 --> 00:10:38,600
then inside these parentheses supply the log directory so we need to point ten support to the folder

119
00:10:38,780 --> 00:10:41,170
where those logs are going to live.

120
00:10:41,360 --> 00:10:48,760
So log underscored the IRR is equal to this value right here.

121
00:10:48,760 --> 00:10:51,120
This is where we've created our folders right.

122
00:10:51,220 --> 00:11:00,280
So Diaw on a score path's is the argument that we're going to feed into this call to tend avoid how.

123
00:11:00,310 --> 00:11:05,770
This is very well and good but we actually probably want to create a new folder every time we train

124
00:11:05,770 --> 00:11:10,180
the model because we're training it made with a slight variation or we're trading one or two or three

125
00:11:10,180 --> 00:11:10,660
or four.

126
00:11:11,020 --> 00:11:18,550
So this ideally should be a function and we know of course how to create functions.

127
00:11:18,550 --> 00:11:27,340
We do that with the DFT would we'll call this function get tense a board and we're gonna supply only

128
00:11:27,340 --> 00:11:33,640
one parameter here and it's going to be the model on discordant names so that way we can vary up the

129
00:11:33,640 --> 00:11:37,990
folder name depending on what input this function gets.

130
00:11:37,990 --> 00:11:45,820
So if I had some curly braces here and change this to model on a screen name then the folder name will

131
00:11:45,820 --> 00:11:52,750
be whatever it is that we've supplied to this function and we can take all of this code.

132
00:11:52,750 --> 00:11:55,210
Now tab it over.

133
00:11:55,390 --> 00:12:03,930
So it all moves and it's inside the body of the function and then we will return the 10 support object.

134
00:12:04,000 --> 00:12:11,640
This is all the work that we need to do to get tense board up and running to actually see tensor board

135
00:12:11,870 --> 00:12:18,310
in action will need to train our model though and we're gonna do just that in the next lesson.

136
00:12:18,330 --> 00:12:19,140
I'll see you there.
